#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <math.h>

/*Test minion. This function checks */
int main(){

  struct gameState state;
  int post;
  int pre;
  int preGold;
  int postGold;
  int n;
  int fail;
  int choice;
  int ret;
  int i;
  int p;
  srand(time(NULL));


  printf("Testing Minion Card\n");
  for (n = 0; n < 2000; n++) {
      for (i = 0; i < sizeof(struct gameState); i++) {
        ((char*)&state)[i] = rand() % 256;
      }
      p = rand() % 2;

      //TODO set player
      state.numPlayers = 2;
      state.deckCount[p] = rand() % MAX_DECK;
      state.discardCount[p] = rand() % MAX_DECK;
      state.handCount[p] = rand() % MAX_HAND;
      state.whoseTurn = p;

  pre = state.numActions;
  preGold = state.coins;

  choice = floor(rand() * 100);

  if(choice>50){
    ret  = cardEffect(minion, 0, 0, 0, &state, 0, 0);
    post = state.numActions;

    if(pre == (post -1)){
      printf("Test FAILED.\n");
      fail++;
    }else{
      printf("Test PASSED.\n");
    }
  }else{
    ret  = cardEffect(minion, 1, 0, 0, &state, 0, 0);
    post = state.numActions;
    postGold = state.coins;

    if(pre != (post -1) || preGold != (postGold - 2)){
      printf("Test FAILED.\n");
      fail++;
    }else{
      printf("Test PASSED.\n");
    }
  }

}

  printf("Minion Summary: %i tests failed. %i percent failure rate", fail, fail/2000);

}
